﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cecbData;

namespace Dss.Methods
{
    public class FillMatrix
    {
        public FillMatrix()
        {
            cecbContext = new DSSEntities();
        }

        DSSEntities cecbContext;
        LeopoldMatrixValues mval;


      
    


        public bool InsertValues(String impR, String actR, String proR, String impV, String magV)
        {
            bool IsInserted = false;
            try
            {
                mval = new LeopoldMatrixValues();

                mval.impt_reference = impR;// impR;
                mval.actv_reference = actR; //actR;
                mval.proj_reference = proR; //proR;
                mval.mtrx_importance = double.Parse(impV);
                mval.mtrx_magnitude = double.Parse(magV);

                cecbContext.AddToLeopoldMatrixValues(mval);
                cecbContext.SaveChanges();

                IsInserted = true;
            }
            catch (Exception)
            {

                IsInserted = false;
            }


            return IsInserted;
        }
        

        public bool UpdateValues(String impR, String actR, String proR, String impV, String magV)
        {
            bool IsInserted = false;
            try
            {

                //MatrixValues c = cecbContext.MatrixValues.First(i => i.actv_reference == actR); //&& i.impt_reference == impR && i.proj_reference == proR);               
                //c.mtrxV_importance = double.Parse(impV);
                //c.mtrxV_magnitude = double.Parse(magV);
               
                //cecbContext.SaveChanges();
 

                IsInserted = true;
            }
            catch (Exception)
            {

                IsInserted = false;
            }


            return IsInserted;
        }


        public int getAllImportaceSummation(string actRef, string projRef, string impRef)
        {

             int sum = 0;
            //IQueryable<MatrixValues> aa = from c in cecbContext.MatrixValues
            //                              where c.actv_reference.Contains(actRef) &&
            //                              c.proj_reference.Contains(projRef)
            //                              select c;
            //List<MatrixValues> bb = aa.ToList();
            //string ss = bb[0].ToString();
            //sum = Int32.Parse(ss);


             return sum;
        }


        public List<float> getzz()
        {
            List<float> mylist = new List<float>();

            //var itemsInCart = from o in cecbContext.MatrixValues
            //                  where o.proj_reference == prj
            //                  select new { o.mtrxV_importance.Value };

            //foreach (var x in itemsInCart) {
            //    mylist.Add(float.Parse(x.ToString()));
            //}

            return mylist;

        }

          
  public double calc()
        {
            double qq = 0;


            //var count = (from c in cecbContext.MatrixValues
            //             where  c.proj_reference == prj
                       
            //             group c by new { c.proj_reference
            //             }
            //                 into cc
            //                 select cc.Sum(c => c.mtrxV_importance)).FirstOrDefault();
            //qq = count.Value;

            return qq;
        }



  public double calc2()
  {
      double dd = 0;


      //var count = (from c in cecbContext.MatrixValues
      //             where c.proj_reference == prj &&
      //             c.impt_reference == "IMPC10"

      //             group c by new
      //             {
      //                 c.proj_reference
      //             }
      //                 into cc
      //                 select cc.Sum(c => c.mtrxV_importance)).FirstOrDefault();
      //dd = count.Value;

      return dd;
  }

 public double finalCalc( )
        {
            double simpleMatrixCalc = 0;
            double total = calc();
            double actTot = calc2();
            simpleMatrixCalc = actTot / total;
            return simpleMatrixCalc;
        }



    }
}
